import qs from 'qs'
export function listerPageClose (callback) {
    if(!callback) {
        console.error('callback is must be')
        return
    }
    // 仅对PC端有效
    window.addEventListener('beforeunload', () => {
        callback()
    }, false)

    var u = navigator.userAgent;
    var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
    var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
    if (isAndroid) {
        // 刷新，最小化，关闭标签 任务管理器，杀进程 都有效
        window.addEventListener('visibilitychange', (e) => {
            callback()
        }, false)
    } else if (isiOS) {
        // 刷新 最小化 
        window.addEventListener('visibilitychange', () => {
            callback()
        }, false)
    }

}


export function navSendBeacon(data) {
    const blob = new Blob([qs.stringify(data)], {
        type: "application/x-www-form-urlencoded; charset=UTF-8",
    });
    navigator.sendBeacon("http://cdw.xmlifa.com/face/wxSmallApp/art/userHisLeave", blob);
}